﻿using Common.Exceptions;
using Microsoft.AspNetCore.Mvc;
using OpenIddict.Client;
using ProductService.Services;
using ProductService.Services.Dtos;
using SeckillService.Services;
using SeckillService.Services.Dtos;
using Servicecomb.Saga.Omega.Abstractions.Transaction;
using Volo.Abp.Application.Dtos;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.ObjectMapping;
using WebSite_Aggregate.Services.Dtos;

namespace ProductService.Controllers;

/// <summary>
/// 秒杀详情控制器(秒杀详情接口)
/// </summary>
[Route("ebusinessseckills/seckilldetail")]
public class SeckillDetailController : AbpController
{
    public IProductService productService { get; set; }

    public ISeckillService seckillService { get; set; }

    public SeckillDetailController()
    {

    }

    /// <summary>
    /// 秒杀商品
    /// </summary>
    /// <param name="SeckillProductId"></param>
    /// <returns></returns>
    [HttpGet("SeckillProductDetails")]
    public async Task<SeckillProductDetailsDto> GetSeckillProductDetailsAsync(Guid SeckillProductId)
    {
        SeckillProductDto dto = await seckillService.GetSeckillProductAsync(SeckillProductId);
        SeckillProductDetailsDto seckillProductDetailsDto = ObjectMapper.Map<SeckillProductDto, SeckillProductDetailsDto>(dto);
        ProductDto productDto = await productService.GetAsync(dto.ProductId);
        seckillProductDetailsDto.SeckillPrice = productDto.ProductPrice;
        seckillProductDetailsDto.SeckillDescription = productDto.ProductDescription;
        return seckillProductDetailsDto;
    }
}
